
package stratego.java.ssm.piece;

import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 * <code>public class BlockPiece extends Piece</code>
 * <p>
 * A BlockPiece denotes that this position on the board cannot be occupied by any other piece
 * </p>
 * 
 * @author Mark Aligbe
 * 
 */
public class BlockPiece extends Piece
{
	private static VolatileImage	img;
	protected static BufferedImage	orig;
	
	/**
	 * <code>public BlockPiece()</code>
	 * <p>
	 * Constructs a Piece with a rank of -1.
	 * </p>
	 */
	public BlockPiece()
	{
		super(-1);
		if (img == null)
		{
			BufferedImage img = null;
			try
			{
				// A cross platform way to get to the desired image. Unix uses \, whereas Windows
				// uses /
				File folder = new File("img");
				File file = new File(folder, "swamp.jpg");
				img = ImageIO.read(file);
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			orig = img;
			BlockPiece.img =
			        GraphicsEnvironment
			                .getLocalGraphicsEnvironment()
			                .getDefaultScreenDevice()
			                .getDefaultConfiguration()
			                .createCompatibleVolatileImage(img.getWidth(), img.getHeight(),
			                        img.getTransparency());
			BlockPiece.img.getGraphics().drawImage(img, 0, 0, null);
		}
	}
	
	@Override
	public boolean isBomb()
	{
		return false;
	}
	
	@Override
	public boolean isFlag()
	{
		return false;
	}
	
	@Override
	public boolean isSpy()
	{
		return false;
	}
	
	@Override
	public boolean isScout()
	{
		return false;
	}
	
	@Override
	public boolean isMiner()
	{
		return false;
	}
	
	@Override
	public boolean isEmpty()
	{
		return false;
	}
	
	@Override
	public boolean isBlock()
	{
		return true;
	}
	
	@Override
	public String toString()
	{
		return "Block";
	}
	
	@Override
	public Image getImage()
	{
		return img;
	}
	
	public Image getOriginalImage()
	{
		return orig;
	}
	
	@Override
	public Image getBack()
	{
		return null;
	}
}
